/*
 * create:2016年4月21日 下午2:00:00
 * author:wangds  
 */
package com.cxkj.shop.biz;

import java.util.Map;

import javax.servlet.http.HttpSession;

import com.cxkj.shop.form.DefaultDelivery;
import com.cxkj.shop.form.Delivery;
import com.cxkj.shop.model.user.DefaultWxUserIntAsset;
import com.cxkj.shop.model.user.User;
import com.cxkj.shop.utils.BusinessUtils;
import com.cxkj.shop.utils.UserUtils;

import net.wangds.comp.business.http.AbstractHttpInteractionBusiness;

/**
 * .
 * 
 * @author wangds
 *
 */
public class LoadCustomerBusiness extends AbstractHttpInteractionBusiness<Object, Delivery> {

  /*
   * @see net.wangds.common.processor.Processor#process()
   * 
   * @author wangds 2016年4月21日 下午2:01:06.
   */
  @Override
  public void process() throws Exception {
    DefaultDelivery<? super User> res = new DefaultDelivery<User>();
    HttpSession ssn = BusinessUtils.getHttpSessionFromHttpBusiness(this);
    String open_id = BusinessUtils.getOpenIdSession(ssn);

    DefaultWxUserIntAsset user = UserUtils.selectUserByOpenId(open_id);
    
    try{
    Map<String, Object> wxuser = BusinessUtils.getUserInfoFromSession(ssn);
    user.setNickname((String)wxuser.get("nickname"));
    user.setSex(((Double)Double.parseDouble(String.valueOf(wxuser.get("sex")))).intValue());
    }catch(Exception e){
      user.setNickname("测试用户");
      user.setSex(0);
    }
    res.setData(user);
    res.setPostTs(System.currentTimeMillis());
    res.setSuccess(true);
    this.setOutput(res);

  }

}
